<?php
namespace app\supermanager\controller;
use think\Request;
/**
 * 提现
 */
class GetCash extends \think\Controller
{
	use \app\common\traits\controller\TraitController;
	const APPLY_STATUS    = 0;//申请中
	const PASSED_STATUS   = 1;//申请通过提现中
	const REFUSED_STATUS  = -1;//申请拒绝
	const COMPLETE_STATUS = 2;//提现完成
	protected function init(){
		if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
		$this->model = model('Cashing');
	}
	
	/**
	 * 提现申请列表
	 */
	public function getIndex(Request $request){
		$list = $this->model->getCashingList($request->get(['status'=>self::APPLY_STATUS]));
	    return view('get_cash/index',['list'=>$list]);
	}
	
	/**
	 * 提现申请通过列表
	 */
	public function getPassIndex(Request $request){
		$list = $this->model->getCashingList($request->get(['status'=>self::PASSED_STATUS]));
	    return view('get_cash/pass_index',['list'=>$list]);
	}
	
	/**
	 * 提现成功列表
	 */
	public function getFinishIndex(Request $request){
		$list = $this->model->getCashingList($request->get(['status'=>self::COMPLETE_STATUS]));
	    return view('get_cash/finish_index',['list'=>$list]);
	}
	
	/**
	 * 提现失败列表
	 */
	public function getFailedIndex(Request $request){
		$list = $this->model->getCashingList($request->get(['status'=>self::REFUSED_STATUS]));
	    return view('get_cash/failed_index',['list'=>$list]);
	}
	
	/**
	 * 提现详情
	 */
	public function getRead(){
		$getCashInfo = $this->model->where('id',input('get.id'))->find();
		$balance = model('Capitals')->where('user_id',$getCashInfo['user_id'])->value('amount');
	    return view('get_cash/read',['getCashInfo'=>$getCashInfo,'balance'=>$balance]);
	}
	
	/**
	 * 申请提现修改数据
	 * 通知会员
	 */
	public function postApplyIndex(Request $request){
	   	$data = $this->model->where(['id'=>$request->post('id'),'status'=>self::APPLY_STATUS])->find();
		if(!$data){
			return false;
		}
		$status = $this->model->passed($request->post('id'));
		if($status){
			$this->success('申请通过','/cashs/passindex');
		}
		$this->error('申请失败');
	}
	
	/**
	 * 提现成功修改数据
	 * 通知会员
	 */
	public function postIndex(Request $request){
		$data = $this->model->where(['id'=>$request->post('id'),'status'=>self::PASSED_STATUS])->find();
		if(!$data){
			return false;
		}
		$status = $this->model->complete(input('post.id'));
		if($status){
			$this->success('提现成功','/cashs/finishindex');
		}
		$this->error('提现失败');
	}
	
	/**
	 * 提现失败修改数据
	 * 通知会员
	 */
	public function postFailedIndex(Request $request){
	    $data = $this->model->where(['id'=>$request->post('id'),'status'=>self::PASSED_STATUS])->find();
		if(!$data){
			return false;
		}
		$status = $this->model->refused(input('post.id'));
		if($status){
			$this->success('提现成功','/cashs/failedIndex');
		}
		$this->error('提现失败');
	}
}
 
 
 

?>